#ifndef NGF_ENGINE_H_
#define NGF_ENGINE_H_

#include <fstream>
#include "message.h"
#include "params.h"


class NeuralGraphicsFileInterface {
private:
	Message* 	message;
	Parameters*	parameters;

	int real_height, real_width; 		// real height/width of the image
	int sample_count_h, sample_count_w;	// number of samples height/width 
	
	int hidden_count;					// number of hidden neurons
	int output_width;					// output size height 
	int output_height;					// output size width
	int color;
	
	int has_errors;
	
	double** weights;
	double** outputs;
	int weights_size;
	int outputs_size;
	int weights_internal_size;
	int outputs_internal_size;
	
	int areWeightsOutputsAllocated();
	void freeWeightsOutputs();
	
	int readNGFFileInternal();
	int writeNGFFileInternal();
	
public:
	NeuralGraphicsFileInterface(Message* msg, Parameters* params);
	~NeuralGraphicsFileInterface();
	
	// read the neural network file
	void readNGFFile();
	int getRealHeight();
	int getRealWidth();
	int getHiddenNeuronCount();
	int getOutputNeuronMatrixHeight();
	int getOutputNeuronMatrixWidth();
	int getOutputSampleHeight();
	int getOutputSampleWidth();
	int getColor();
	double* getOutputNeuronWeight(int neuron);
	double* getPreOutputSample(int sampleno);
	
	// write the neural network file
	void writeNGFFile();
	void setRealSize(int height, int width);
	void setHiddenNeuronCount(int hidden);
	void setOutputMatrixSize(int height, int width);
	void setSampleMatrixSize(int sample_h, int sample_w);
	void setColor(int isColor);	
	
	void allocateWeightsOutputs();
	
	void setOutputNeuronWeight(int neuron, double* weights);
	void setPreOutputSample(int sampleno, double* sample);

	
	int hasErrors();
};

#endif /*NGF_ENGINE_H_*/
